layui.use(['form', 'layer', 'dropdown'], function () {
    const form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        dropdown = layui.dropdown;

    //左侧菜单点击事件，其中 docDemoMenu1 对应的是菜单结构上的 id 指
    dropdown.on('click(docDemoMenu1)', function (options) {
        var othis = $(this); //当前菜单列表的 DOM 对象
        console.log(options); //菜单列表的 lay-options 中的参数
        switch (options.id) {
            case 1:
                window.location.href = "archives01.html";
                break;
            case 2:
                window.location.href = "archives02.html";
                break;
            case 3:
                window.location.href = "archives03.html";
                break;
        }
    });

    setTimeout(function () {
        $.ajax({
            url: $.cookie("tempUrl") + "hSysDoctor/selectByPrimaryKey?id=" + $.cookie("doctorId"),
            type: "GET",
            success: function (result) {
                if (result.code === 200) {
                    //给表单赋值
                    form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                        "videoPrice": result.data.videoPrice // "name": "value"
                        , "textPrice": result.data.textPrice
                    });
                } else {
                    layer.msg("个人资料获取失败", {icon: 7, anim: 6});
                }
            }
        });
    }, 500);

    form.on("submit(addNews)", function (data) {
        //获取表单区域所有值
        var data1 = form.val("formTest");
        console.log(data1)
        $.ajax({
            url: $.cookie("tempUrl") + "hSysDoctor/updateByPrimaryKeySelectiveForPrice",
            type: "PUT",
            datatype: "application/json",
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify({
                id: $.cookie("doctorId"),
                videoPrice: data1.videoPrice,
                textPrice: data1.textPrice
            }),
            success: function (result) {
                if (result.code === 200) {
                    layer.msg("更新成功");
                } else {
                    layer.msg("请求失败", {icon: 7, anim: 6});
                }
            }
        });
        return false;
    });
});
